<template>
	<BaseContainer
		class="report-table-wrapper"
		v-loading="loading"
		element-loading-text="加载中..."
		element-loading-background="rgba(255, 255, 255, 0.8)"
	>
		<div class="t-header">
			<div @click="drawer = !drawer" class="article-title">
				<span>浦口区养老服务机构从业人员岗位津贴申请表</span>
			</div>
		</div>
		<ReportTable :column="dataList" :isDetail="true" :moreNewsModel="moreNewsModel" :baseModel="baseModel" :model="modelData" @change="handleSave">
			<template v-slot:staffPhoto>
				<div style="width: 100px">
					<img style="width: 100px" :src="modelData.staffPhoto" alt="" />
				</div>
			</template>
			<template v-slot:note>
				<div class="w-100 tr flex-column" style="min-height: 120px; line-height: 60px">
					<div class="p-r-50">
						<p style="padding-right: 3vw">单位：（章）</p>
						<p style="padding-right: 6vw">年 月 日</p>
					</div>
				</div>
			</template>
			<template v-slot:note2>
				<div class="w-100 tr flex-column" style="min-height: 120px; line-height: 60px">
					<div class="p-r-50">
						<p style="padding-right: 3vw">区民政部门：（章）</p>
						<p style="padding-right: 3vw">年 月 日</p>
					</div>
				</div>
			</template>
		</ReportTable>
		<OrgArchives ref="orgArchivesEl"></OrgArchives>
		<!-- 从业人员档案 -->
		<aplid-dialog 
		:append-to-body="true" 
		v-model="staffInfoShow" 
		whickComm="detail"
		:customeHeader="detailConfig?.customeHeader"
		:model="modelData"
		title="从业人员档案" 
		width="85%">
		<PractitionerArchives :now-row-data="modelData"></PractitionerArchives>
		</aplid-dialog>
	</BaseContainer>
</template>

<script setup lang="ts">
import ReportTable from '@/views/instOperate/components/ApplyReport/components/ReportTable/index.vue'
import OrgArchives from '@/views/instOperate/components/ApplyReport/components/OrgArchives/index.vue'
import apiMod from '@/apiMod'
import { filterEmptyObj,dealBigMoney } from '@/utils/util'
import PractitionerArchives from '@/views/instOperate/components/ApplyReport/practitioner/Archives/index.vue'
// import PractitionerArchives from '@/views/datacenter/basicData/practitioner/Archives/index.vue'
import bus from '@/utils/eventbus'

const props = defineProps<{
	params?: any
	creditCode?: string | number
	editData?: any
	isDetail?: boolean
	caseId?: string | number
	custome?: boolean
	approvalStatus?: string | number
	otherData?:any
	isPigeonhole?:boolean
}>()
const emit = defineEmits(['save'])

let staffInfoShow = ref(false)
const detailConfig = {
	customeHeader: {
		integrityConfig: {
			baseTableName: 'dp_foundation_practitioners',
			materialTableName: 'dp_foundation_practitioners_material',
			soleValue: 'idCard',
		},
		type: 'CardTwo',
		title: 'staffName',
		avatar: 'staffPhoto',
		tipList: [{ prop: 'phone', type: 'tip-success', label: '联系电话' }],
		tagList: [
			// { prop: 'healthyStateLabel', code: 'HEALTHY_STATE', custome: 'tag', type: 'success', label: '健康状态' },
			{ prop: 'workTypeLabel', code: 'WORK_TYPE', custome: 'tag', type: 'success', label: '工作类型' },
			{ prop: 'serviceStateLabel', code: 'SERVICE_STATE', custome: 'tag', type: 'success', label: '服务状态' },
			{ prop: 'organizationName', type: 'success', label: '所在单位' },
		]
	},
}
const model = ref({
	year: '',
	month: '',
})
const drawer:any = ref(false)
const baseModel: any = shallowRef({})
const loading:any = ref(false)
const modelData: any = ref({})
const orgArchivesEl = ref(null)
let moreNewsModel: any = ref({})

const tableColumnConfig = (data?: any) => {
		return [
			[
				{ m: '姓名',style:{width:'180px'} },
				{
					m: '',
					style:{width:'180px'},
					prop: 'staffName',
					archives: true,
					archivesText: '档案',
					showLink: (col, model) => {
						staffInfoShow.value = true
					},
					mc: {
						rs: 1,
						cs: 3,
					},
				},
				{ m: '性别', style: { width: '180px' } },
				{
					m: '',
					style:{width:'180px'},
					setColor: true,
					prop: 'genderLabel',
					mc: {
						rs: 1,
						cs: 2,
					},
				},
				{
					m: '照片',
					prop: 'staffPhoto',
					mc: {
						rs: 4,
						cs: 1,
					},
				},
			],

			[
				{ m: '身份证号' },
				{
					m: '',
					prop: 'idCard',
					setColor: true,
					mc: {
						rs: 1,
						cs: 3,
					},
				},
				{ m: '民族' },
				{
					m: '',
					setColor: true,
					prop: 'nationalLabel',
					mc: {
						rs: 1,
						cs: 2,
					},
				},
			],
			[
				{ m: '出身日期' },
				{
					m: '',
					setColor: true,
					prop: 'birthday',
					mc: {
						rs: 1,
						cs: 3,
					},
				},
				{ m: '文化程度' },
				{
					m: '',
					prop: 'cultureDegreeLabel',
					setColor: true,
					mc: {
						rs: 1,
						cs: 2,
					},
				},
			],
			[
				{ m: '联系电话' },
				{
					m: '',
					prop: 'phone',
					setColor: true,
					mc: {
						rs: 1,
						cs: 3,
					},
				},
				{ m: '养老工作起始年月' },
				{
					setColor: true,
					m: '',
					prop: 'elderlyCareWorkTime',
					mc: {
						rs: 1,
						cs: 2,
					},
				},
			],
			[
				{
					m: '从业社会保险连续缴纳起始年月',
					mc: {
						rs: 1,
						cs: 4,
					},
				},
				{
					setColor: true,
					m: '',
					prop: 'socialSecurityTime',
					mc: {
						rs: 1,
						cs: 4,
					},
				},
			],
			[
				{ m: '资格证书名称及等级', mc: { rs: 1, cs: 2 } },
				{ m: '', prop: 'qualificationCertificateNameAndGrade', mc: { rs: 1, cs: 2 } },
				{ m: '编号', style: { width: '180px' } },
				{ m: '', prop: 'qualificationCertificateCode', mc: { rs: 1, cs: 3 } },
			],
			[
				{ m: '养老护理专业技术职称等级', mc: { rs: 1, cs: 2 } },
				{ m: '', prop: 'nursingNameAndGrade', mc: { rs: 1, cs: 2 } },
				{ m: '编号', style: { width: '180px' } },
				{ m: '', prop: 'nursingCode', mc: { rs: 1, cs: 3 } },
			],
			[
				{
					m: '上半年',
					mc: {
						rs: 2,
						cs: 1,
					},
				},
				{ m: '领取月份' },
				{
					m: '10(上年度)',
				},
				{
					m: '11(上年度)',
				},
				{
					m: '12(上年度)',
				},
				{
					m: '1',
				},
				{
					m: '2',
				},
				{
					m: '3',
				},
			],
			[
				{ m: '补贴金额' },
				{
					m: '',
					propName: modelData.value.month == 4 ? modelData.value.subsidyAmount1 : '',
				},
				{
					m: '',
					propName: modelData.value.month == 4 ? modelData.value.subsidyAmount2 : '',
				},
				{
					m: '',
					propName: modelData.value.month == 4 ? modelData.value.subsidyAmount3 : '',
				},
				{
					m: '',
					propName: modelData.value.month == 4 ? modelData.value.subsidyAmount4 : '',
				},
				{
					m: '',
					propName: modelData.value.month == 4 ? modelData.value.subsidyAmount5 : '',
				},
				{
					m: '',
					propName: modelData.value.month == 4 ? modelData.value.subsidyAmount6 : '',
				},
			],
			[
				{
					m: '下半年',
					mc: {
						rs: 2,
						cs: 1,
					},
				},
				{ m: '领取月份' },
				{
					m: '4',
				},
				{
					m: '5',
				},
				{
					m: '6',
				},
				{
					m: '7',
				},
				{
					m: '8',
				},
				{
					m: '9',
				},
			],
			[
				{ m: '补贴金额' },
				{
					m: '',
					propName: modelData.value.month == 10 ? modelData.value.subsidyAmount1 : '',
				},
				{
					m: '',
					propName: modelData.value.month == 10 ? modelData.value.subsidyAmount2 : '',
				},
				{
					m: '',
					propName: modelData.value.month == 10 ? modelData.value.subsidyAmount3 : '',
				},
				{
					m: '',
					propName: modelData.value.month == 10 ? modelData.value.subsidyAmount4 : '',
				},
				{
					m: '',
					propName: modelData.value.month == 10 ? modelData.value.subsidyAmount5 : '',
				},
				{
					m: '',
					propName: modelData.value.month == 10 ? modelData.value.subsidyAmount6 : '',
				},
			],
			[
				{ m: '补贴总金额：', align: 'left', mc: { rs: 1, cs: 4 }, propName: modelData.value.subsidyTotalAmount },
				{ m: '大写：', align: 'left', mc: { rs: 1, cs: 4 }, propName:modelData.value.subsidyTotalAmountBig  },
			],
			[
				{
					m: '用人单位意见',
				},
				{
					m: '',
					prop: 'note',
					mc: {
						rs: 1,
						cs: 7,
					},
				},
			],
			[
				{
					m: '审批意见',
				},
				{
					m: '',
					prop: 'note2',
					mc: {
						rs: 1,
						cs: 7,
					},
				},
			],
		]
}
const dataList = ref(tableColumnConfig())


const getInitData = async () => {
	const params = props.params || {}
	
	if ((props.approvalStatus == 1 || !props.approvalStatus)&&!props.isPigeonhole) {
		try {
			const query = {
				year: '',
				month: '',
				creditCode: params.organizationId|| props.otherData.creditCode,
				idCard: params.applicateObject || props.otherData.staffIdCard,
				// projectId: props.params.subsidyProjectId,
			}
			if (params.belongDate) {
				query.year = params.belongDate.replace('年', '-').replace('月', '').split('-')[0]
				query.month = params.belongDate.replace('年', '-').replace('月', '').split('-')[1]
			}
			
			loading.value = true
			const uptoData = await apiMod.view_subsidy_postAllowance(query).then((res) => res.data)
			bus.emit('postListData',uptoData)
			loading.value = false
			const resultData = uptoData
			modelData.value = uptoData
			// 处理大写
			if(resultData.subsidyTotalAmount&&!resultData.subsidyTotalAmountBig){
				resultData.subsidyTotalAmountBig = dealBigMoney(resultData.subsidyTotalAmount)
				// 编辑信息
				let query = {
					id:props.editData.result_case_id,
					dataContent: modelData.value,
					dataResults: modelData.value,
					fromId: props.editData.formId,
					fromType: "PK_staff_post_report",
					tableTemplateId: "PK_staff_post_report",
					projectId:props.params.subsidyProjectId,
				}
				await apiMod.view_formResults_edit(query)
			}
			
			baseModel.value = JSON.parse(JSON.stringify(resultData))
			const reportData = filterEmptyObj(resultData)
			if (uptoData.dataContent) {
				moreNewsModel.value = {
					...uptoData.dataContent,
					viewStatus: uptoData?.viewStatus,
				}
			} else {
				moreNewsModel.value = {
					viewStatus: uptoData?.viewStatus,
				}
			}
			
			dataList.value = tableColumnConfig(reportData)
				handleSave()
		} catch (error) {
			loading.value = false
		}
	} else if(props.isPigeonhole){
		modelData.value = props.editData
		dataList.value = tableColumnConfig(modelData.value)
	} else if(props.editData.result_case_id){
		modelData.value = props.editData
		
		if(modelData.value.subsidyTotalAmount&&!modelData.value.subsidyTotalAmount){
			modelData.value.subsidyTotalAmountBig = dealBigMoney(modelData.value.subsidyTotalAmount)
				// 编辑信息
				let query = {
					id:props.editData.result_case_id,
					dataContent: modelData.value,
					dataResults: modelData.value,
					fromId: props.editData.formId,
					fromType: "PK_staff_post_report",
					tableTemplateId: "PK_staff_post_report",
					projectId:props.params.subsidyProjectId,
				}
				await apiMod.view_formResults_edit(query)
			}
		dataList.value = tableColumnConfig(modelData.value)
	}
	bus.emit('waitSubmitPostListData',modelData.value)
}
onMounted(() => {
	if (props.params) getInitData()
})

const handleSave = () => {
	emit('save', modelData.value, 'PK_staff_post_report', props.editData)
}

onUnmounted(() => {})
</script>

<style scoped lang="scss">
.report-table-wrapper {
	width: 100%;
	margin: 0 auto;
	padding: 10px 30px;
	top: 0;

	.t-header {
		text-align: center;
		font-size: 18px;
		font-weight: bold;
		padding: 15px 0;

		.text-sm {
			font-weight: 400;
			font-size: 16px;
		}
	}
}

.article-title {
	position: relative;
	z-index: 0;
	width: 63%;
	margin: 0 auto;
}

.text-tip {
	--base-text-bg: rgb(56 176 255 / 13%);
	position: absolute;
	width: 100%;
	height: 100%;
	background: var(--base-text-bg);
	padding: 4px;
	z-index: -1;
	&:hover {
		cursor: pointer;
	}
	.tip-text-new {
		position: absolute;
		right: 0;
		top: -10px;
		color: #fff;
		border-radius: 4px;
		padding: 2px;
		width: 40px;
		background-color: #ed6d05;
	}
	.tip-text-detail {
		background-color: #179fe3;
		position: absolute;
		right: 0;
		top: -10px;
		color: #fff;
		border-radius: 4px;
		padding: 2px;
		width: 40px;
	}
}
</style>
